package com.xuecheng.learning.controller;

import com.xuecheng.api.learning.CourseRecordApi;
import com.xuecheng.api.learning.model.dto.CourseRecordDTO;
import com.xuecheng.api.learning.model.vo.ResourceUrlModel;
import com.xuecheng.common.domain.page.PageRequestParams;
import com.xuecheng.common.domain.page.PageVO;
import com.xuecheng.learning.common.utils.UAASecurityUtil;
import org.springframework.web.bind.annotation.*;
import com.xuecheng.learning.service.CourseRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * <p>
 * 选课记录 前端控制器
 * </p>
 *
 * @author itcast
 */
@Slf4j
@RestController
@RequestMapping
public class CourseRecordController implements CourseRecordApi {

    @Autowired
    private CourseRecordService  courseRecordService;

    @GetMapping("/learnedRecords/myCourseRec/{coursePubId}")
    public CourseRecordDTO getCourseRecordByCoursePuId(@PathVariable Long coursePubId) {

        //获得用户名
        String username = UAASecurityUtil.getUser().getUsername();

        return courseRecordService.getCourseRecordByCoursePuId(coursePubId, username);
    }

    @GetMapping("resource-url")
    public ResourceUrlModel playUrl(Long coursePubId, Long teachplanId, Long mediaId) {
        //获得用户名
        String username = UAASecurityUtil.getUser().getUsername();

        return courseRecordService.playUrl(coursePubId, teachplanId, mediaId, username);
    }

    @PostMapping("learnedRecords/list")
    public PageVO<CourseRecordDTO> queryCourseRecordList(PageRequestParams params) {
        //获得用户名
        String username = UAASecurityUtil.getUser().getUsername();

        return courseRecordService.queryCourseRecordList(params, username);
    }

    @GetMapping("learnedRecords/recentLearnedUsers")
    public List<CourseRecordDTO> recentLearnedUsers(Long coursePubId) {

        //获得机构id
        Long companyId = UAASecurityUtil.getCompanyId();

        return courseRecordService.recentLearnedUsers(coursePubId, companyId);
    }


}
